/**
  *@File文件:AuthImageController.java
  *@Date日期:2017年7月20日 上午10:43:17
  *@Copyright版权:Corporation 2017
  */
package com.qiaomengapp.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.qiaomengapp.util.VerifyCodeUtils;

/**
 *@Description描述:
 *@Author作者 jinxin
 *@Date日期:2017年7月20日
 */
@Controller
public class AuthImageController {
	
	@RequestMapping("/authImage")
	public void createAuthImage(HttpServletRequest request,HttpServletResponse response){
		 response.setHeader("Pragma", "No-cache"); 
	     response.setHeader("Cache-Control", "no-cache"); 
	     response.setDateHeader("Expires", 0); 
	     response.setContentType("image/jpeg"); 
	           
	     //生成随机字串 
	     String verifyCode = VerifyCodeUtils.generateVerifyCode(4); 
	     //存入会话session 
	     HttpSession session = request.getSession(true); 
	     //删除以前的
	     session.removeAttribute("verCode");
	     session.setAttribute("verCode", verifyCode.toLowerCase()); 
	     //生成图片 
	     int w = 100, h = 30; 
	     try {
			VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	   
	}
}
